package com.wb.mas.ui.success;

import android.content.Intent;
import android.os.Bundle;

import androidx.lifecycle.ViewModelProviders;

import com.wb.mas.BR;
import com.wb.mas.R;
import com.wb.mas.app.AppViewModelFactory;
import com.wb.mas.databinding.ActSuccessBinding;

import me.goldze.mvvmhabit.base.BaseActivity;

/**
 * Copyright (C) 2018,
 * WebViewActivity
 * <p>
 * Description
 *
 * @author yue
 * @version 1.0
 * <p>
 * Ver 1.0, 2019-05-08, yue, Create file
 */
public class SuccessActivity extends BaseActivity<ActSuccessBinding, SuccessViewModel> {

    public static final int TYPE_AUTH = 0;

    public static final int TYPE_BORROW = 1;

    private int type;


    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.act_success;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initParam() {
        super.initParam();
        Intent intent = getIntent();
        type = intent.getIntExtra("type", TYPE_AUTH);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (type == TYPE_AUTH) {
            viewModel.titleText.set(getString(R.string.success_auth_title));
        } else {
            viewModel.titleText.set(getString(R.string.success_borrow_title));
        }
    }


    @Override
    public SuccessViewModel initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        SuccessViewModel successViewModel = ViewModelProviders.of(this, factory).get(SuccessViewModel.class);
        successViewModel.type = type;
        return successViewModel;
    }

    @Override
    public void onBackPressed() {
        viewModel.backJump();
    }
}
